<template>
  <div>
    <router-link to="/" tag="div" class="header-abs" v-show="showAbs">
      <span class="iconfont header-abs-back">&#xe622;</span>
    </router-link>
    <div class="header-fixed" v-show="!showAbs" :style="opacityStyle">
      <router-link to="/">
        <div class="iconfont header-fixed-back">&#xe622;</div>
      </router-link>
      景点详情
    </div>
  </div>
</template>

<script>
export default {
  name: 'DetailHeader',
  data () {
    return {
      showAbs: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  activated () {
    document.body.scrollTop = 0
    window.addEventListener('scroll', this.handleScroll)
  },
  methods: {
    handleScroll () {
      let bodyTop = document.body.scrollTop
      if (bodyTop >= 42) {
        if (bodyTop <= 140) {
          let opacity = bodyTop / 140
          this.opacityStyle = {
            opacity
          }
        }
        this.showAbs = false
      } else {
        this.showAbs = true
      }
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import "~styles/varibles.styl"
  .header-abs
    position: absolute
    left: .16rem
    top: .16rem
    width: .6rem
    height: .6rem
    border-radius: .3rem
    background: rgba(0, 0, 0, .6)
    text-align: center
    line-height: .6rem
    .header-abs-back
      color: #fff
      font-size .36rem
  .header-fixed
    position: fixed
    top 0
    left: 0
    right: 0
    height: .86rem
    line-height: .86rem
    text-align: center
    color: #ffffff
    background-color: $bgColor
    font-size .32rem
    .header-fixed-back
      width: .8rem
      font-size .4rem
      position: absolute
      left: 0
      top: 0
      color: #ffffff
</style>
